import logging
import os
import shutil


def logger(filename,name = __name__):
    if os.path.exists(filename):
        shutil.rmtree(filename)
    os.makedirs(f'{filename}/img')

    logger = logging.getLogger(__file__)
    logger.setLevel(logging.DEBUG)
    file = logging.FileHandler(f'{filename}/{name}.log', encoding='utf-8')
    file.setLevel(logging.DEBUG)
    logger.addHandler(file)
    log_formatter = logging.Formatter(fmt='%(asctime)s %(levelname)8s ''%(filename)s:%(lineno)d | %(message)s',
                                      datefmt='%Y-%m-%d %H:%M:%S')
    file.setFormatter(log_formatter)
    return logger
